<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

class JFX_Module_Blockstyle_Property_Font extends JFX_Module_Blockstyle_Property_Base
{
	public $id = 'font';
	public $cssName = 'font';
	public $title = 'Font';
	public $instanceId = 'block-font-0';
	
	

	public function init(){
		$fontVariantWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$fontVariantWidget->name = 'Font Variant';
		$fontVariantWidget->instanceId = $this->instanceId.'-font-variant';
		$fontVariantWidget->cssName = 'font-variant';
		$fontVariantWidget->multiple = false;
		$fontVariantWidget->addOption('Normal', 'normal');
		$fontVariantWidget->addOption('Small Caps', 'small-caps');
		$fontVariantWidget->addOption('Inherit', 'inherit');
		$this->widgets[] = $fontVariantWidget;

		$fontStyleWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$fontStyleWidget->name = 'Font Style';
		$fontStyleWidget->instanceId = $this->instanceId.'-font-style';
		$fontStyleWidget->cssName = 'font-style';
		$fontStyleWidget->multiple = false;
		$fontStyleWidget->addOption('Normal', 'normal');
		$fontStyleWidget->addOption('Italic', 'italic');
		$fontStyleWidget->addOption('Oblique', 'oblique');
		$fontStyleWidget->addOption('Inherit', 'inherit');
		$this->widgets[] = $fontStyleWidget;

		$fontFamilyWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$fontFamilyWidget->name = 'Font Family';
		$fontFamilyWidget->instanceId = $this->instanceId.'-font-family';
		$fontFamilyWidget->cssName = 'font-family';
		$fontFamilyWidget->multiple = false;
		$fontFamilyWidget->addOption('Arial, "sans-serif"', 'Arial, arial, "sans-serif"');
		$fontFamilyWidget->addOption('Times New Roman, Times, serif', '"Times New Roman", Times, serif');
		$fontFamilyWidget->addOption('Courier, monospace', 'Courier, monospace');
		$fontFamilyWidget->addOption('Cursive', 'cursive');
		$fontFamilyWidget->addOption('Fantasy', 'fantasy');
		$this->widgets[] = $fontFamilyWidget;

		$fontSizeWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$fontSizeWidget->unit = 'px';
		$fontSizeWidget->name = 'Font Size';
		$fontSizeWidget->instanceId = $this->instanceId.'-font-size';
		$fontSizeWidget->cssName = 'font-size';
		$fontSizeWidget->units = array(
			'px',
			'%',
			'pt',
			'pc',
			'in',
			'ex',
			'em',
			'cm',
			'mm'
		);
		$fontSizeWidget->unitNames = array(
			'Pixels',
			'Percent',
			'Point',
			'Pica',
			'Inch',
			'EX',
			'EM',
			'CM',
			'MM'
		);
		$this->widgets[] = $fontSizeWidget;


		$fontWeightWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$fontWeightWidget->unit = 'px';
		$fontWeightWidget->name = 'Font Weight';
		$fontWeightWidget->instanceId = $this->instanceId.'-font-weight';
		$fontWeightWidget->cssName = 'font-weight';
		$fontWeightWidget->step = 100;
		$fontWeightWidget->min = 100;
		$fontWeightWidget->max = 900;
		$fontWeightWidget->units = array(
			'exact',
			'normal',
			'bold',
			'bolder',
			'lighter'
		);
		$fontWeightWidget->unitNames = array(
			'Exact',
			'Normal',
			'Bold',
			'Bolder',
			'Lighter'
		);
		$this->widgets[] = $fontWeightWidget;






	}

	public function getCssValue(){


	}

	public function __toCss(){
		$outputString = '';

		if(!$this->hasEnabledWidget()){
			return $outputString;
		}

		if(!$this->hasEnabledWidget() || $this->cssName=='' || $this->cssName != $this->id){
			return '/*not enabled '.$this->cssName.'*/ '.$outputString;
		}

		$fontFamilyWidget = $this->getWidget($this->instanceId.'-font-family');
		if($fontFamilyWidget->enabled){
			$outputString .= '	font-family : '.$fontFamilyWidget->values[0].";\n";
		}

		$fontStyleWidget = $this->getWidget($this->instanceId.'-font-style');
		if($fontStyleWidget->enabled){
			$outputString .= '	font-style : '.$fontStyleWidget->values[0].";\n";
		}

		$fontVariantWidget = $this->getWidget($this->instanceId.'-font-variant');
		if($fontVariantWidget->enabled){
			$outputString .= '	font-variant : '.$fontVariantWidget->values[0].";\n";
		}




		$fontSizeWidget = $this->getWidget($this->instanceId.'-font-size');
		if($fontSizeWidget->enabled){
			$outputString .= '	font-size : '.$fontSizeWidget->value.$fontSizeWidget->unit.";\n";
		}

		$fontWeightWidget = $this->getWidget($this->instanceId.'-font-weight');
		if($fontWeightWidget->enabled){
			if($fontWeightWidget->unit=='exact'){
				$outputString .= '	font-weight : '.$fontWeightWidget->value.";\n";
			}else{
				$outputString .= '	font-weight : '.$fontWeightWidget->unit.";\n";
			}
		}



		return $outputString;
	}


	public function setPropertyFromJson($k, $v){
		if(!in_array($k, $this->privateProperties)){
			$this->$k = $v;
		}

		try{
		
		}catch(Exception $e){
			JFX::addError('Cant add the '.$k);
			
		}
		
	}

	public function prepareJson(){
		parent::prepareJson();
		$imageWidget = $this->getWidget($this->instanceId.'-image');
		$imageWidget->buildImageList();
	}


}

